package com.ahwei.common.sentinel.config;

import com.ahwei.common.rest.util.ResponseUtils;
import com.ahwei.common.sentinel.aspect.GlobalRestExceptionAdvice;
import com.ahwei.common.sentinel.handler.GlobalBlockExceptionHandler;
import com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration;
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>
 * Sentinel自动配置类。！
 * </p>
 *
 * @author ahWei
 * @email：ahwei163@qq.com
 * @since 2022-06-06 14:14:45
 */
@Configuration(proxyBeanMethods = false)
@AutoConfigureBefore(SentinelFeignAutoConfiguration.class)
public class SentinelAutoConfiguration {
    /**
     * Sentinel对统一异常处理的AOP增强
     * @return .
     */
    @Bean
    public GlobalRestExceptionAdvice restExceptionAdvice() {
        return new GlobalRestExceptionAdvice();
    }

    @Bean
    @ConditionalOnMissingBean
    public BlockExceptionHandler blockExceptionHandler() {
        return new GlobalBlockExceptionHandler();
    }

    @Bean
    public ResponseUtils responseUtils(){
        return new ResponseUtils();
    }
}
